# -*- coding: utf-8 -*-
"""
@Author: 王少杰
@Date: 2025/8/28
@Time: 14:57
@FileName: register_page.py
@描述:
"""
import time
import random

from selenium.webdriver.common.by import By
from src.pages.base_page import BasePage
class RegisterPage(BasePage):
    # 点击注册
    register_button = (By.XPATH, '//*[@id="app"]/div[2]/div[2]/div[4]')
    #公司名称
    register_ltd = (By.NAME, 'companyName')
    #手机号
    register_phone = (By.NAME, 'phone')
    #密码
    register_password = (By.NAME, 'pass')
    #确认密码
    register_true_password = (By.NAME, 'confirmPass')
    #验证码
    register_yzmCode = (By.NAME, 'yzmCode')
    #立即注册
    register_now = (By.ID, 'submit-btn')

    def register(self, companyName, companyPhone, companyPassword, companyTruePassword):
        # 定位注册按钮并点击
        self.find_ele_explicitly(self.register_button).click()
        # 定位公司名称，并输入
        self.find_ele_explicitly(self.register_ltd).send_keys(companyName)
        # 定位手机号，并输入
        self.find_ele_explicitly(self.register_phone).send_keys(companyPhone)
        # 定位密码，并输入
        self.find_ele_explicitly(self.register_password).send_keys(companyPassword)
        # 定位确认密码，并输入
        self.find_ele_explicitly(self.register_true_password).send_keys(companyTruePassword)
        time.sleep(10)
        # 定位验证码，并输入
        code = input("请输入验证码: ")
        self.find_ele_explicitly(self.register_yzmCode).send_keys(code)
        # 定位立即注册，并点击
        self.find_ele_explicitly(self.register_now).click()
        time.sleep(10)

    @staticmethod
    def random_phone():
        # 常见中国大陆手机号段
        prefix = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
                  "150", "151", "152", "153", "155", "156", "157", "158", "159",
                  "170", "171", "172", "173", "175", "176", "177", "178",
                  "180", "181", "182", "183", "185", "186", "187", "188", "189"]
        return random.choice(prefix) + ''.join(random.choices("0123456789", k=8))

    # 示例
    for _ in range(5):
        print(random_phone())


if __name__ == '__main__':
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get('https://jxc.aesd.cn/login')

    phone = RegisterPage.random_phone()
    print("生成的随机手机号:", phone)

    RegisterPage(driver).register('中软国际',phone,'wsj1747419241!','wsj1747419241!')

